<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">合同管理</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :model="form" label-width="auto" :inline="true" size="mini">
                    <el-form-item label="档案编号:">
                        <div style="width: 200px">
                            <el-input v-model="form.dabh" placeholder="请输入档案编号" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="合同名称:">
                        <div style="width: 200px">
                            <el-input v-model="form.htmc" placeholder="请输入合同名称" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="房屋地址:">
                        <div style="width: 200px">
                            <el-input v-model="form.fwdz" placeholder="请输入房屋地址" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="合同金额:">
                        <div style="width: 200px">
                            <el-col :span="11">
                                <el-input v-model="form.numa" @keyup.enter.native="onSearch"></el-input>
                            </el-col>
                            <el-col class="line" :span="2" style="text-align: center"
                                ><span style="font-size: 8px; text-align: center">--</span></el-col
                            >
                            <el-col :span="11">
                                <el-input v-model="form.numb" @keyup.enter.native="onSearch"></el-input>
                            </el-col>
                        </div>
                    </el-form-item>
                    <el-form-item label="合同类型:">
                        <el-select v-model="form.htlx" placeholder="请选择合同类型" style="width: 100%" clearable @change="onSearch">
                            <el-option v-for="(item, index) in htlxlist" :key="index" :label="item.name" :value="item.code"> </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="开始时间:">
                        <div style="width: 200px">
                            <el-date-picker
                                type="date"
                                placeholder="选择开始时间"
                                v-model="form.startTime"
                                style="width: 100%"
                                value-format="yyyy-MM-dd"
                                @change="onSearch"
                            ></el-date-picker>
                        </div>
                    </el-form-item>
                    <el-form-item label="结束时间:">
                        <div style="width: 200px">
                            <el-date-picker
                                type="date"
                                placeholder="选择结束时间"
                                v-model="form.endTime"
                                style="width: 100%"
                                value-format="yyyy-MM-dd"
                                @change="onSearch"
                            ></el-date-picker>
                        </div>
                    </el-form-item>
                    <!-- :disabled="getfgyShow" -->
                    <el-form-item label="房管员:">
                        <div style="width: 190px">
                            <el-select v-model="form.fgy" placeholder="请选择房管员" clearable @change="onSearch" >
                                <el-option v-for="item in fgylist" :key="item.id" :label="item.name" :value="item.id"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search" class="searchcolor">查询</el-button>
                        <el-button @click="reSearch" icon="el-icon-refresh" class="searchcolor">重置</el-button>
                        <el-button type="primary" @click="downloadlist" icon="el-icon-download" class="searchcolor">导出</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <!-- max-height="330" -->
            <el-table
                :data="tableData"
                style="width: 100%"
                :header-cell-style="tableHeaderColor"
                :row-style="tablerowColor"
                :row-class-name="tableRowClassName"
                :cell-style="tablecellColor"
                border
                :max-height="maxHeight"
            >
                <el-table-column prop="dabh" label="档案编号" align="center" width="200" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="fwdz" label="地址" align="center" width="200" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="htmc" label="合同名称" align="center" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="htlx" label="合同类型" align="center" width="160"> </el-table-column>
                <el-table-column prop="htje" label="合同金额" align="center"> </el-table-column>
                <el-table-column prop="sznum" label="收支数量 " align="center"> </el-table-column>
                <el-table-column prop="szwtgnum" label="收支未通过数量 " align="center">
                    <template slot-scope="scope">
                        <span :style="{ color: scope.row.szwtgnum > 0 ? 'red' : '' }">
                            {{ scope.row.szwtgnum }}
                        </span>
                    </template>
                </el-table-column>
                <!-- <el-table-column prop="ysje" label="已收金额" align="center" width="200"></el-table-column> -->
                <el-table-column label="操作" width="160" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="gotodetail(scope.row.id)">详情</el-button>
                        <el-button type="text" size="small" @click="gotodetailadd(scope.row.id)" v-if="szshow">收支录入</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination
                    background
                    layout="total,prev, pager, next,jumper"
                    :total="total"
                    :current-page.sync="current"
                    :page-size="pageSize"
                    @current-change="handleCurrentChange"
                >
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { otherlist, dbnodelete, otherexport, getfgyList } from '@/api/index';
import valueList from '@/components/common/valueList.vue';
export default {
    name: 'swcxlist',
    data() {
        return {
            getfgyShow: false, //房管员判断
            fgylist: [], //房管员列表
            szshow: false,
            ssswlist: valueList.ssswlist, //所属事物列表
            htlxlist: valueList.htlxlist,
            yhlxlist: valueList.yhlxlist1,
            total: 0,
            current: 1,
            pageSize: 10,
            form: {
                bf: '', //丙方 ,
                buildid: '', //房屋ID ,
                create_name: '', //创建人 ,
                create_name_id: '', //创建人id ,
                create_time: '', //创建时间 ,
                current: 1, //第几页 ,
                dabh: '', //档案编号 ,
                fj: '', //附件 ,
                fwdz: '', //房屋地址 ,
                htdqsj: '', //合同到期时间 ,
                htje: '', //合同金额 ,
                htlx: '', //合同类型 ,
                htmc: '', //合同名称 ,
                htqdsj: '', //合同签订时间 ,
                htqssj: '', //合同起始时间 ,
                id: '', //id ,
                jf: '', //甲方 ,
                pageSize: 10, //每页数量 ,
                status_code: '', //1正常 2删除 ,
                szqk: '', // 收支情况 ,
                update_name: '', //修改人 ,
                update_name_id: '', //修改人id ,
                update_time: '', //修改时间 ,
                yf: '', //乙方
                numa: '', //金额A
                numb: '', //金额B
                startTime: '', //开始时间
                endTime: '', //结束时间
                fgy: '',
            },
            tableData: [],

            ztlist: [
                { name: '是', code: 1 },
                { name: '否', code: 0 }
            ],
            maxHeight: null,
            type: this.$store.getters.type
        };
    },
    components: {},
    computed: {},
    methods: {
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;';
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black';
        },
        tablecellColor() {
            return 'font-weight:700;color:#000000;border-color:#c0c0c0';
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row'; //这是类名
            } else {
                return '';
            }
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.otherlist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.otherlist(this.form);
            console.log('搜索');
        },
        // 重置
        reSearch() {
            this.current = 1;
            this.form = {
                bf: '', //丙方 ,
                buildid: '', //房屋ID ,
                create_name: '', //创建人 ,
                create_name_id: '', //创建人id ,
                create_time: '', //创建时间 ,
                current: 1, //第几页 ,
                dabh: '', //档案编号 ,
                fj: '', //附件 ,
                fwdz: '', //房屋地址 ,
                htdqsj: '', //合同到期时间 ,
                htje: '', //合同金额 ,
                htlx: '', //合同类型 ,
                htmc: '', //合同名称 ,
                htqdsj: '', //合同签订时间 ,
                htqssj: '', //合同起始时间 ,
                id: '', //id ,
                jf: '', //甲方 ,
                pageSize: 10, //每页数量 ,
                status_code: '', //1正常 2删除 ,
                szqk: '', // 收支情况 ,
                update_name: '', //修改人 ,
                update_name_id: '', //修改人id ,
                update_time: '', //修改时间 ,
                yf: '', //乙方
                numa: '', //金额A
                numb: '', //金额B
                startTime: '', //开始时间
                endTime: '', //结束时间
                // fgy: this.$store.getters.role == '10011' ? this.$store.getters.userId : '',
                fgy:''
            };
            this.otherlist(this.form);
            console.log('搜索');
        },
        // 项目列表
        otherlist(data) {
            otherlist(data).then((res) => {
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    if (
                        this.$store.getters.role == '10011' ||
                        this.$store.getters.role == '30004' ||
                        this.$store.getters.role == '30005' ||
                        this.$store.getters.role == '30009' ||
                        this.$store.getters.role == '30010'||
                        this.$store.getters.role == '30006'||
                        this.$store.getters.role == '30007'||
                        this.$store.getters.role == '10020'
                    ) {
                        this.szshow = true;
                    }
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = { id: e.id };
                    dbnodelete(data).then((res) => {
                        if (res.code == 200) {
                            this.otherlist(this.form);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 跳转流程页面
        gotodetail(id) {
            let name = 'otherhtdetail';
            this.$router.push({
                name: name,
                query: { id: id }
            });
        },
        // 跳转信息录入页面
        gotodetailadd(id) {
            let name = 'htgldetailadd';
            this.$router.push({
                name: name,
                params: { id: id }
            });
        },
        // 导出
        downloadlist() {
            otherexport(this.form).then((res) => {
                const link = document.createElement('a');
                let blob = new Blob([res], {
                    type: 'application/vnd.ms-excel'
                });
                link.style.display = 'none';
                //设置连接
                link.href = URL.createObjectURL(blob);
                link.download = '合同管理导出文件';
                document.body.appendChild(link);
                //模拟点击事件
                link.click();
            });
        },
        // 获取房管员列表
        getfgyList() {
            let data = {};
            getfgyList(data).then((res) => {
                if (res.code == 200) {
                    this.fgylist = res.data;
                    if (this.$store.getters.role == '10011') {
                        console.log(this.$store.getters.userId);
                        // this.form.fgy = this.$store.getters.userId;
                        this.getfgyShow = true;
                    } else {
                        this.getfgyShow = false;
                    }
                    this.otherlist(this.form);
                    console.log(res.data);
                } else {
                    this.$message.error = '获取数据失败！！';
                }
            });
        }
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 360;
        });
        // 获取房管员列表
        this.getfgyList();
        console.log(this.$store.getters);

        console.log(valueList);
    }
};
</script>

<style scoped>
.container {
    /* height: calc(100vh - 260px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}

.unloadTitle {
    text-align: left;
    padding-bottom: 10px;
    box-sizing: border-box;
    color: #606266;
}
</style>

<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>
